#include "../headers/Main.h"
#include "../headers/ResString.h"
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* DLL Loader From FlakCommon Exports */
/* Credits to M0tah					 */

vector<CResString> vDLLs;
//Load Dll File(szFLConfigFile From Function void LoadSettings() in Main.cpp)
void HkLoadDLLConf(const char *szFLConfigFile)
{
	vDLLs.clear();
	vDLLs.push_back(CResString(string(".\\") + (char*)((char*)GetModuleHandle(0) + 0x256C4))); //typically .\\resources.dll
	INI_Reader ini;
	if(ini.open(szFLConfigFile, false))
	{
		while(ini.read_header())
		{
			if(ini.is_header("Resources"))
			{
				while(ini.read_value())
				{
					if(ini.is_value("DLL"))
					{
						vDLLs.push_back(CResString(string(".\\") + ini.get_value_string(0)));
					}
				}
			}
		}
		ini.close();
	}
}

// @iIDS = Item Hash Code
EXPORT string HkGetStringFromIDS(uint iIDS) //Only works for names
{
	if(!iIDS)
		return "";

	uint iDLL = iIDS / 0x10000;
	iIDS -= iDLL * 0x10000;
	if(vDLLs[iDLL].GetStringBlock((iIDS / 16) + 1, 0) != 1000)
		return "";
	return vDLLs[iDLL].GetString(iIDS - ((iIDS / 16) * 16));
}

// @iIDS = Item Hash Code
EXPORT wstring HkGetWStringFromIDS(uint iIDS) //Only works for names
{
	if(!iIDS)
		return L"";

	uint iDLL = iIDS / 0x10000; 
	iIDS -= iDLL * 0x10000;
	if(vDLLs[iDLL].GetStringBlock((iIDS / 16) + 1, 0) != 1000)
		return L"";
	return vDLLs[iDLL].GetWString(iIDS - ((iIDS / 16) * 16));
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////